From d29910068c7da960a39c769b94300d02832d93b5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 10 Jul 2014 11:50:03 -0700 Subject: [PATCH] Fix filtering for test deps This fixes `cargo test` to only test the *local* package --- src/cargo/ops/cargo_rustc.rs | 7 +++++-- tests/test_cargo_test.rs | 38 ++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/cargo/ops/cargo_rustc.rs b/src/cargo/ops/cargo_rustc.rs index ff7aa6a3f..d8be4f11a 100644 --- a/src/cargo/ops/cargo_rustc.rs +++ b/src/cargo/ops/cargo_rustc.rs @@ -105,7 +105,10 @@ pub fn compile_targets<'a>(env: &str, targets: &[&Target], pkg: &Package, // Only compile lib targets for dependencies let targets = dep.get_targets().iter().filter(|target| { - target.is_lib() && target.get_profile().get_env() == env + target.is_lib() && match env { + "test" => target.get_profile().is_compile(), + _ => target.get_profile().get_env() == env, + } }).collect::>(); jobs.push((dep, try!(compile(targets.as_slice(), dep, &mut cx)))); @@ -121,7 +124,7 @@ pub fn compile_targets<'a>(env: &str, targets: &[&Target], pkg: &Package, fn compile(targets: &[&Target], pkg: &Package, cx: &mut Context) -> CargoResult<(Freshness, Job)> { - debug!("compile_pkg; pkg={}; targets={}", pkg, pkg.get_targets()); + debug!("compile_pkg; pkg={}; targets={}", pkg, targets); if targets.is_empty() { return Ok((Fresh, proc() Ok(()))) diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 07a9f0e4f..77f90feb5 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -57,27 +57,49 @@ test!(test_with_lib_dep { }) test!(test_with_deep_lib_dep { - let p = project("foo") + let p = project("bar") .file("Cargo.toml", r#" - [project] + [package] name = "bar" version = "0.0.1" authors = [] [dependencies.foo] - path = "foo" + path = "../foo" "#) .file("src/lib.rs", " extern crate foo; - pub fn bar() {} - ") + #[test] + fn bar_test() { + foo::foo(); + } + "); + let p2 = project("foo") .file("Cargo.toml", r#" - [project] + [package] name = "foo" version = "0.0.1" authors = [] "#) - .file("src/lib.rs", ""); + .file("src/lib.rs", " + pub fn foo() {} - assert_that(p.cargo_process("cargo-test"), execs().with_status(0)); + #[test] + fn foo_test() {} + "); + + p2.build(); + assert_that(p.cargo_process("cargo-test"), + execs().with_status(0) + .with_stdout(format!("\ +{compiling} foo v0.0.1 (file:{dir}) +{compiling} bar v0.0.1 (file:{dir}) + +running 1 test +test bar_test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\ + ", + compiling = COMPILING, + dir = p.root().display()).as_slice())); }) -- 2.30.2